import { curl } from "@/utils";

// 获取博客列表
const getBlog = async ({
  page = 1,
  limit = 10,
  categoryid = -1,
  keyword = "",
} = {}) =>
  await curl.get("/api/blog", {
    params: {
      page: page,
      limit: limit,
      categoryid: categoryid,
      keyword: keyword,
    },
  });

// 获取博客分类列表
const getBlogCategory = async () => await curl.get("/api/blogtype");

// 获取博客详情
const getBlogDetail = async (id) => await curl.get(`/api/blog/${id}`);

//提交博客评论
const postBlogComment = async ({ nickname, content, blogId }) =>
  await curl.post(`/api/comment`, {
    content: content,
    nickname: nickname,
    blogId: blogId,
  });

//获取评论列表
const getBlogComment = async ({
  page = 1,
  limit = 10,
  blogId = -1,
  keyword = "",
} = {}) =>
  await curl.get(`/api/comment`, {
    params: {
      page,
      limit,
      blogId,
      keyword,
    },
  });

export {
  getBlog,
  getBlogCategory,
  getBlogDetail,
  postBlogComment,
  getBlogComment,
};
